#include <stdio.h>
#include <memory.h>

int main( )
{
    int t, i, s, s2;
    __int64 n, n2;
    int score[ 101 ];
    while ( scanf("%I64d", &n) != EOF )
    {
        memset( score, 0, sizeof( score ) );
        while ( scanf("%I64d%d", &n2, &s) != EOF )
        {
            if ( n2 == 0 && s == 0 ) break;
            if ( n2 == n ) s2 = s;
            else score[ s ]++;
        }
        t = 1;
        for ( i = 100; i > s2; i-- )
            t += score[ i ];
        printf("%d\n", t);
    }
    return 0;
}
